home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
minix
/
up1510b.tgz
/
up1510b
/
src
/
lib
/
posix
/
closedir.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-19
|
760b
|
33 lines
/* closedir -- close a directory stream Author: D.A. Gwyn */
/* last edit: 11-Nov-1988 D A Gwyn */
#include <stddef.h>
#include <errno.h>
#include <sys/types.h>
#include <limits.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
typedef char *pointer; /* (void *) if you have it */
#define DULL (DIR *) NULL
#define CULL (char *) NULL
int closedir(dirp)
register DIR *dirp; /* stream from opendir() */
{
register int fd;
if (dirp == DULL || dirp->dd_buf == CULL || dirp->dd_magic != _DIR_MAGIC) {
errno = EBADF;
return(-1); /* invalid pointer */
}
fd = dirp->dd_fd; /* bug fix thanks to R. Salz */
dirp->dd_magic = 0; /* invalidate the entry */
free((pointer) dirp->dd_buf);
free((pointer) dirp);
return(close(fd));
}